package src.main.java.org.Arrays;


import java.util.Arrays;
import java.util.Comparator;

public class ArrayTest2 {
    public static void main(String[] args) {
        Student[] students = new Student[4];
        students[0] = new Student("蜘蛛精",169.5,23);
        students[1] = new Student("紫霞",163.8,25);
        students[2] = new Student("紫霞",163.8,25);
        students[3] = new Student("赵四",162.5,28);

//        对象排序第一种方法
/*        Arrays.sort(students);
        System.out.println(Arrays.toString(students));*/
        //        对象排序第二种方法
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                /*if(o1.getHeight()>o2.getHeight()){
                    return 1;
                }else if(o1.getHeight()>o2.getHeight()){
                    return -1;
                }
                return 0;*/

                return Double.compare(o1.getHeight(),o2.getHeight());
            }
        });
    }
}
